package 测试;

import java.util.HashSet;
import java.util.Set;

public class Test2 {

    //全排列
    public int sum=0;
    void all(int a[], int r[], Set<Integer> set){
        int now = set.size();
        if(now==a.length){
            sum++;
            for (int i : r) {
                System.out.printf("%d ",i);
            }
            System.out.println(" ");
            return;
        }
        for (int t : a) {
            if(!set.contains(t)){
                r[now]=t;
                set.add(t);
                all(a,r,set);
                set.remove(t);
            }
        }
    }
    public static void main(String[] args) {
        int[] a = new int[]{1,2,3};
        int[] r = new int[a.length];
        Set<Integer> set = new HashSet<>();
        Test2 test2 = new Test2();
        test2.all(a,r,set);
        System.out.println("共有"+test2.sum+"种排列");

    }
}
